﻿using System;
using System.Collections.Generic;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using AMS.DataAccess.Interfaces;
using AMS.DataAccess.Filters;
using AMS.DataAccess.BO;
using AMS.DataAccess.Filter;
using AMS.DataAccess;

public partial class Customer_GetCustomerDlg : BaseWorkPage
{
    protected void Page_Load(object sender, EventArgs e)
    {
        Utils.ParseIntQueryString(Request, "type", ref customerType);
        if (!IsPostBack)
        {
            DoDataBind();
        }
    }

    const int CustomerTypeCustomer = 0;
    const int CustomerTypeApplicant = 1;
    int customerType;
    private const int GridViewRowCount = 10;

    void DoDataBind()
    {
        ICustomerManager mgr = ManagerFactory.CreateCustomerManager();
        QuerySimpleCustomerFilter filter = new QuerySimpleCustomerFilter();
        if (customerType == CustomerTypeApplicant)
        {
            filter.OnlyGetApplicant = false;
        }
        else
        {
            filter.OnlyGetCustomer = true;
        }

        filter.LimitedRowCount = GridViewRowCount;
        if (txtCustomerName.Text != string.Empty)
        {
            filter.CustomerName = new StringFilterField(txtCustomerName.Text, StringOperations.Like);
            filter.CustomerNameE = filter.CustomerName;
        }

        List<CustomerInfo> customers = mgr.GetCustomerSimpleList(CallContext, filter);
        gv.DataSource = customers;
        gv.DataBind();

        if (customers.Count >= GridViewRowCount)
        {
            lblMsg.Text = "查询的记录数大于" + GridViewRowCount + ", 请缩小查询范围";
        }
    }
    protected void btnSearch_Click(object sender, EventArgs e)
    {
        DoDataBind();
    }
}
